package cn.jekun.shop.app.action;

import javax.annotation.Resource;

import cn.jekun.component.base.bean.ErrorMsg;
import cn.jekun.component.base.exceptions.BusinessException;
import cn.jekun.component.shop.service.OrderService;
import net.sf.json.JSONObject;

/**
 * 提醒
 * @author twj
 *
 */
@SuppressWarnings("serial")
public class RemindAction extends AppBaseAction{
	
	
	@Resource(name=OrderService.BEAN_NAME)
	private OrderService orderService;
	
	/**
	 * 用户提醒商家
	 * @return
	 */
	public String remindToShop(){
		JSONObject jsonObject = new JSONObject();
		try {
			String orderId = this.request.getParameter("orderId");
			this.validateSign(getLoginSign(),getUserId(),orderId);//验证签名是否正确 md5(loginSign userId+orderId)
			this.validateLoginApp();//验证是否登录
			jsonObject = orderService.remindToShop(orderId);
			
			this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "手机用户提醒商家发货,订单号"+orderId);//记录操作日志
		} catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	/**
	 * 商家提醒用户
	 * @return
	 */
	public String remindToUser(){
		JSONObject jsonObject = new JSONObject();
		try {
			String orderId = this.request.getParameter("orderId");
			this.validateSign(getLoginSign(),getUserId(),orderId);//验证签名是否正确 md5(loginSign userId+orderId)
			this.validateLoginApp();//验证是否登录
			jsonObject = orderService.remindToUser(orderId);
			this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "手机商家提醒用户收货,订单号"+orderId);//记录操作日志
		} catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}

}
